[% setvar title Allow multiply matched groups in regexes to return a listref of all matches %]
<div id="archive-notice">
    <h3>This file is part of the Perl 6 Archive</h3>
    <p>To see what is currently happening visit <a href="http://www.perl6.org/">http://www.perl6.org/</a></p>
</div>
<div class='pod'>
<a name='TITLE'></a><h1>TITLE</h1>
<p>Allow multiply matched groups in regexes to return a listref of all matches</p>
<a name='VERSION'></a><h1>VERSION</h1>
<pre>  Maintainer: Kevin Walker &lt;<a href='mailto:kwalker@xmission.com'>kwalker@xmission.com</a>&gt;
  Date: 30 Sep 2000
  Mailing List: <a href='mailto:perl6-language-regex@perl.org'>perl6-language-regex@perl.org</a>
  Number: 360
  Version: 1
  Status: Developing</pre>
<a name='DESCRIPTION'></a><h1>DESCRIPTION</h1>
<p>Since the October 1 RFC deadline is nigh, this will be pretty informal.</p>
<p>Suppose you want to parse text with looks like:</p>
<pre>     name: John Abajace
     children: Tom, Dick, Harry
     favorite colors: red, green, blue

     name: I. J. Reilly
     children: Jane, Gertrude
     favorite colors: black, white
 
     ...</pre>
<p>Currently, this takes two passes:</p>
<pre>     while ($text =~ /name:\s*(.*?)\n\s*
     					children:\s*(.*?)\n\s*
     					favorite\ colors:\s*(.*?)\n/sigx) {
         # now second pass for $2 ( = &quot;Tom, Dick, Harry&quot;) and $3, yielding
         # list of children and favorite colors
     }</pre>
<p>If we introduce a new construction, (?@ ... ), which means &quot;spit out a
list ref of all matches, not just the last match&quot;, then this could be
done in one pass:</p>
<pre>     while ($text =~ /name:\s*(.*?)\n\s*
     					children:\s*(?:(?@\S+)[, ]*)*\n\s*
     					favorite\ colors:\s*(?:(?@\S+)[, ]*)*\n/sigx) {
         # now we have:
         #  $1 = &quot;John Abajace&quot;;
         #  $2 = [&quot;Tom&quot;, &quot;Dick&quot;, &quot;Harry&quot;]
         #  $3 = [&quot;red&quot;, &quot;green&quot;, &quot;blue&quot;]
     }</pre>
<p>Although the above example is contrived, I have very often felt the need
for this feature in real-world projects.</p>
<a name='IMPLEMENTATION'></a><h1>IMPLEMENTATION</h1>
<p>Unknown.</p>
<a name='REFERENCES'></a><h1>REFERENCES</h1>
<p>None.</p>
</div>
